package pl.jdeveloper.derivato;

import org.cheffo.jeplite.JEP;
import org.cheffo.jeplite.ParseException;

import pl.jdeveloper.derivato.model.Derivative;

public class JEPDerivative extends Derivative{
	
	private String formula;
	private JEP parserJEP;
	
	@Override
	public double getValue(double arg) {
		double value=0;
		parserJEP.addVariable("x", arg);
		parserJEP.parseExpression(formula);
		try {
			value= parserJEP.getValue();
		} catch (ParseException e) {
			System.out.println("dupa");
		}
		return value;
	}
	
	public JEPDerivative(String formula) {
		super();
		this.formula = formula;
		parserJEP= new JEP();
		parserJEP.addStandardFunctions();
		parserJEP.addStandardConstants();
		parserJEP.addVariable("x", 0);
	}

	public String getFormula() {
		return formula;
	}

	public void setFormula(String formula) {
		this.formula = formula;
	}

}
